import { Badge, Button, message, Popconfirm, Space, TableColumnsType, Tag, Typography } from 'antd'
import type { ITableData } from './types'
import { DIS_STATUSBANDBTNTEXT, QSFORGID, STATUSBAND } from '@/constant'

export const useIndexColumns = (
  onEdit: (info: ITableData) => void,
  onStatus: (info: ITableData) => void,
  viewLogs: (info: ITableData) => void,
  params: Record<string, any>,
): TableColumnsType<ITableData> => [
  {
    title: '组织名称',
    dataIndex: 'name',
    key: 'name',
    align: 'center',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '组织编码',
    dataIndex: 'code',
    key: 'code',
    align: 'center',
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '组织描述',
    dataIndex: 'description',
    key: 'description',
    align: 'center',
    width: 150,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '组织状态',
    dataIndex: 'status',
    key: 'status',
    align: 'center',
    render: (info) => {
      return <Badge status={info == 1 ? 'success' : 'error'} text={STATUSBAND[info] || '-'} />
    },
  },
  {
    fixed: 'right',
    title: '操作',
    width: 230,
    align: 'center',
    render: (info) => {
      {
        // info.id == 1 时 是七色纺组织 不可进行操作
        return (
          <Space size="large">
            {info.id == QSFORGID ? null : (
              <Typography.Link
                onClick={() => {
                  onEdit(info)
                }}
              >
                编辑
              </Typography.Link>
            )}
            <Typography.Link onClick={() => viewLogs(info)}>查看日志</Typography.Link>
            {info.id == QSFORGID ? null : (
              <Popconfirm
                title={`确认${DIS_STATUSBANDBTNTEXT[info.status]}吗？`}
                onConfirm={() => onStatus(info)}
                okText="确认"
                cancelText="取消"
              >
                <Typography.Link type={info.status == 1 ? 'danger' : undefined}>
                  {DIS_STATUSBANDBTNTEXT[info.status]}
                </Typography.Link>
              </Popconfirm>
            )}
          </Space>
        )
      }
    },
  },
]
